package org.example.mianshi;

import java.util.*;

/**
 * @author liyishan
 * @date 2024/10/25 10:30
 * @apiNote
 */

public class jdmianshi {

    public static int deal(int[] nums){
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int num : nums){
            map.put(num,map.getOrDefault(num,0)+1);
        }
        StringBuffer str = new StringBuffer();
        List<Map.Entry<Integer, Integer>> entries = new ArrayList<Map.Entry<Integer, Integer>>(map.entrySet());
        Collections.sort(entries,(o1, o2) -> o2.getKey().compareTo(o1.getKey()));
        int max = 0;
        for (Map.Entry<Integer, Integer> entry : entries){
            if(entry.getValue() %2 == 0){
                for(int i = 0;i<entry.getValue()/2;i++){
                    str.append(String.valueOf(entry.getKey()));
                }
            }else{
                max = Math.max(max,entry.getKey());
            }
        }
        StringBuffer reverse = new StringBuffer();
        for(int i =str.length()-1;i>=0;i--){
            reverse.append(str.charAt(i));
        }
        str.append(String.valueOf(max)).append(reverse);
        return Integer.parseInt(str.toString());
    }

}
